/**
 * @改变数组的行和列
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>

//function declaration
void scalar (int nrows, int ncols, int a[nrows][ncols], int b[ncols][nrows]);
void display (int nrows, int ncols, int a[nrows][ncols]);

int main(int argc, char *argv[]) {
	int ncols = 5;
	int nrows = 3;

	int a[3][5] = {
		{7,16,55,13,12},
		{12,10,52,0,7},
		{-2,1,2,4,9}
	};

	int b[5][3];

	printf("正常显示：\n");
	display(nrows, ncols, a);

	scalar(nrows, ncols, a, b);
	printf("\n交换显示：\n");
	display(ncols, nrows, b);

	printf("\n");
	return 0;
}

void scalar (int nrows, int ncols, int a[nrows][ncols], int b[ncols][nrows]) {
	int row, column;

	for (row=0; row<nrows; row++) {
		for (column=0; column<ncols; column++) {
			b[column][row] = a[row][column];
		}
	}
}

void display (int nrows, int ncols, int a[nrows][ncols]) {
	int row, column;

	for (row=0; row<nrows; row++) {
		for (column=0; column<ncols; column++) {
			printf("%5d",a[row][column]);
		}
		printf("\n");
	}
}

